package com.atguigu.java;

/**
 * 例子：创建三个窗口卖票，总票数为100张
 *
 * 目前存在线程安全问题，待解决
 * @Description
 * @Author codingBee
 * @Date 2020/8/20/7:49
 */
public class WindowTest {
    public static void main(String[] args) {
        Window window1 = new Window("窗口1");
        Window window2 = new Window("窗口2");
        Window window3 = new Window("窗口3");
        window1.start();
        window2.start();
        window3.start();


    }
}

class Window extends Thread {
    private static int ticket = 100;

    public Window(String name) {
        super(name);
    }

    public Window() {
    }

    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                System.out.println(getName() + ":卖票，票号为：" + ticket);
                ticket--;
            } else {
                break;
            }
        }
    }
}